from typing import Dict, Type

from motor.engine_server.config.base import IConfig, ServerConfig
from motor.engine_server.config.vllm import VLLMConfig


class ConfigParser:
    def __init__(self, server_config: ServerConfig):
        self.server_config = server_config
        self._config_class_map: Dict[str, Type[IConfig]] = {
            "vllm": VLLMConfig,
        }

    def parse(self) -> IConfig:
        config_class = self._config_class_map.get(self.server_config.engine_type)

        if not config_class:
            raise ValueError(f"Unsupported engine type: {self.server_config.engine_type}, "
                             f"supported types: {list(self._config_class_map.keys())}")

        config_instance = config_class(server_config=self.server_config)

        config_instance.initialize()
        config_instance.convert()
        config_instance.validate()
        return config_instance
